import { api } from '@/utils/request'
import type { 
  School, 
  SchoolPageParams,
  PageResult,
  ApiResponse,
  SchoolWithStats
} from '@/types'

export class SchoolService {
  /**
   * 分页查询学校列表
   */
  static async getSchoolPage(params: SchoolPageParams): Promise<PageResult<School>> {
    const response = await api.post<PageResult<School>>('/circle/api-admin/sSchool/page', params)
    return response.data
  }

  /**
   * 获取学校详情
   */
  static async getSchoolDetail(id: number): Promise<School> {
    const response = await api.get<School>(`/circle/api-admin/sSchool/get/${id}`)
    return response.data
  }

  /**
   * 获取当前用户管理的学校列表
   */
  static async getSchoolListByUser(): Promise<SchoolWithStats[]> {
    const response = await api.get<SchoolWithStats[]>('/circle/api-admin/sSchool/getSchoolListByUser')
    return response.data
  }

  /**
   * 新增学校
   */
  static async createSchool(schoolData: Partial<School>): Promise<boolean> {
    const response = await api.post<boolean>('/circle/api-admin/sSchool/create', schoolData)
    return response.data
  }

  /**
   * 更新学校
   */
  static async updateSchool(schoolData: Partial<School>): Promise<boolean> {
    const response = await api.post<boolean>('/circle/api-admin/sSchool/update', schoolData)
    return response.data
  }

  /**
   * 删除学校
   */
  static async deleteSchool(id: number): Promise<boolean> {
    const response = await api.delete<boolean>(`/circle/api-admin/sSchool/delete/${id}`)
    return response.data
  }
}

// 默认导出单例实例
export const schoolService = SchoolService 